package com.example.demo.service;

import com.example.demo.entity.Notification;
import com.example.demo.mapper.NotificationMapper;
import com.example.demo.service.NotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationImpl implements NotificationService {

    @Autowired
    private NotificationMapper notificationMapper;

    @Override
    public void addNotification(int user_id, String content) {
        notificationMapper.insertNotification(user_id, content);
    }

    @Override
    public List<Notification> getNotificationsByUserId(int user_id) {
        return notificationMapper.findNotificationsByUserId(user_id);
    }

    public boolean markNotificationAsRead(int user_id, int notification_id) {
        notificationMapper.updateNotificationReadStatus(user_id, notification_id);
        return notificationMapper.findNotificationById(notification_id).is_read();
    }

    public boolean addBulkNotification(List<Integer> user_ids, String content) {
        for (Integer user_id : user_ids) {
            notificationMapper.insertNotification(user_id, content);
        }
        return true;
    }
}